#!/bin/sh

. /opt/cluster/pim_lib
PLOT=$PROG.png
TMPFILE=/tmp/$PROG-$$

grep vsize $(grep -l 'cmdline=".*MATLAB"' $pim_datadir/ment* )  |
sed 's,'$pim_datadir',,' |
awk -F'[_:="][_:="]*' '
	{
		#print $1, $2, $3, $4, $5, $6
		aggfor[$1 " " $2] += $5
		aggcnt[$1 " " $2]++
		#GB=$5/(1024*1024)
	 	#printf ("%s:%6d %6.2fGB\n", $1, $2, GB)
	}
	END {
		for (pidon in aggfor) {
			printf("%s avg: %6.2f MB\n", pidon, (aggfor[pidon]/aggcnt[pidon])/1024)
		}
	}' |
sort -n -k4,4 >$TMPFILE

gnuplot - >/dev/null 2>&1 <<EOF
set terminal png size 800,600
set output "$PLOT"
plot "$TMPFILE" using 4 title "Matlab size in MB"
EOF
rm -f $TMPFILE
